<?php
	include_once('header.php');
	// start 修改设置信息
	if ($_SERVER['REQUEST_METHOD']=='POST') {
		$default_category_id = $_POST['default_category_select'];
		$textarea_height = (int)($_POST['textarea_height_text']);
		$new_image_align = $_POST['image_align_radio'];
		$new_image_width = (int)$_POST['image_width_text'];


		$query_default_category = "update `setting` set `value`=".$default_category_id." where `name`='default_category_id'";
		$query_textarea_height = "update `setting` set `value`=".$textarea_height." where `name`='textarea_height'";
		$mysql_connection->query($query_default_category);
		$mysql_connection->query($query_textarea_height);

		$query_new_image_align = "update `setting` set `value`='".$new_image_align."' where `name`='image_align'";
		$query_new_image_width = "update `setting` set `value`='".$new_image_width."' where `name`='image_width'";
		$mysql_connection->query($query_new_image_align);
		$mysql_connection->query($query_new_image_width);
	}
	// end 修改设置信息

	// start 重置 setting[] 的内容
	$new_setting = get_setting($mysql_connection);
	// end 重置 setting[] 的内容
?>
<div id="content_b"><form action="<?php echo $_SERVER['PHP_SELF'];?>?message_box=撰写设置更新成功" method="post"><table border="0" width="100%">
	<tr><td>编辑框尺寸</td>
	<td colspan="2"><input type="text" name="textarea_height_text" class="input_text" value="<?php echo $new_setting['textarea_height'];?>" /></td></tr>
	<tr><td>默认分类</td>
	<td colspan="2"><select name="default_category_select">
		<?php
			$category_array = select_category($mysql_connection);
			foreach ($category_array as $category_setting['id'] => $category_setting['name']) {
				if ($new_setting['default_category_id']==$category_setting['id']) {
				?>
				<option selected="selected" id="<?php echo $category_setting['id'];?>" value="<?php echo $category_setting['id'];?>"><?php echo $category_setting['name'];?></option>
				<?php
				} else {
				?>
				<option id="<?php echo $category_setting['id'];?>" value="<?php echo $category_setting['id'];?>"><?php echo $category_setting['name'];?></option>
				<?php
				}
			}
		?>
	</select></td></tr>
	<tr><td colspan="3">图像设置</td></tr>
	<tr><td></td><td>图像默认大小设置</td><td><input type="text" name="image_width_text" class="input_text" value="<?php echo $new_setting['image_width'];?>" /></td></tr>
	<tr><td></td><td>图像默认位置设置</td>
	<?php
		if ($new_setting['image_align']== 'left') {
		?>
		<td><input type="radio" checked name="image_align_radio" value="left" />&nbsp;居左
		<input type="radio" name="image_align_radio" value="center" />&nbsp;居中
		<input type="radio" name="image_align_radio" value="right" />&nbsp;居右
		<?php
		} else if ($new_setting['image_align']=='center') {
		?>
		<td><input type="radio" name="image_align_radio" value="left" />&nbsp;居左
		<input type="radio" checked name="image_align_radio" value="center" />&nbsp;居中
		<input type="radio" name="image_align_radio" value="right" />&nbsp;居右
		<?php
		} else if ($new_setting['image_align']=='right') {
		?>
		<td><input type="radio" name="image_align_radio" value="left" />&nbsp;居左
		<input type="radio" checked name="image_align_radio" value="center" />&nbsp;居中
		<input type="radio" checked name="image_align_radio" value="right" />&nbsp;居右
		<?php
		}
	?>
	</td></tr>
</table>
<input type="submit" value="保存修改" />
</form></div>
<?php include_once('footer.php');?>
